/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upc.clase.demo.service.impl;

import edu.upc.clase.demo.dao.FulbitoFacilException;
import edu.upc.clase.demo.dao.RegistrarCanchaDao;
import edu.upc.clase.demo.entity.Cancha;
import edu.upc.clase.demo.service.RegistrarCanchaService;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author Omar
 */
@Service
public class RegistrarCanchaServiceImpl implements RegistrarCanchaService {

    private static Logger log = LoggerFactory.getLogger(RegistrarCanchaServiceImpl.class);
    @Autowired
    private RegistrarCanchaDao registrarCanchaDao;

    @Override
    public Integer insertar(Cancha cancha) {
        try {
            log.info("Registrando Cancha");

            Cancha canchaRetorna;
            canchaRetorna = registrarCanchaDao.buscarPorNombreyLocal(cancha);

            if (canchaRetorna == null) {
                return registrarCanchaDao.insertar(cancha);
            } else {
                throw new FulbitoFacilException("Esta nombre de cancha ya existe en el local");
            }
        } catch (Exception e) {
            return null;
        }
    }
}
